#pragma once

#include <vector>

class Convert
{
public:
    static bool a2w(LPCSTR source, int srcSize, std::vector<wchar_t>& dest)
    {
        ATLASSERT(srcSize);

        long count = MultiByteToWideChar(CP_ACP, 0, source, srcSize, NULL, 0);
        if (!count || count == ERROR_NO_UNICODE_TRANSLATION) 
            return false;

        dest.assign((count + 1) * sizeof(wchar_t), 0);

        int ret = MultiByteToWideChar(CP_ACP, 0, source, srcSize, (LPWSTR)&dest[0], count);
        if (!ret || ret == ERROR_NO_UNICODE_TRANSLATION)
            return false;

        return true;
    }

    static bool w2a(const std::vector<wchar_t>& source, std::vector<char>& dest)
    {
        ATLASSERT(source.size());

        int count = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)&source[0], source.size(), NULL, 0, NULL, NULL );
        if (!count)
            return false;

        dest.assign(count, 0);

        int ret = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)&source[0], source.size(), (LPSTR)&dest[0], count, NULL, NULL );
        if (!ret)
            return false;

        return true;
    }    
};